package cn.com.gridinfo.sooc.core.expand.feedback.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.widget.ImageView;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import cn.com.gridinfo.sooc.R;
import cn.com.gridinfo.sooc.base.BaseSoocActivity;
import cn.com.gridinfo.sooc.core.expand.feedback.fragment.MySuggestionFragment;
import cn.com.gridinfo.sooc.core.expand.feedback.fragment.SummitSuggestionFragment;
import cn.com.gridinfo.sooc.utils.PagerAdapter;

/**
 * 意见反馈界面
 *
 * @author yingchunli
 */
public class FeedbackActivity extends BaseSoocActivity {

    @InjectView(R.id.sliding_tabs_signin)
    TabLayout tabLayout;//标签栏
    @InjectView(R.id.viewpager_signin)
    ViewPager mViewPager;//ViewPager
    PagerAdapter adapter;//适配器
    String[] tabText = {"提交反馈", "我的反馈"};// 选修卡文字

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.expand_feedback);
        ButterKnife.inject(this);

        initView();
    }

    /**
     * 初始化界面数据
     */
    void initView() {
        adapter = new PagerAdapter(getSupportFragmentManager());
        adapter.addFragment(SummitSuggestionFragment.newInstance(""), tabText[0]);
        adapter.addFragment(MySuggestionFragment.newInstance(""), tabText[1]);

        for (int i = 0; i < tabText.length; i++) {
            tabLayout.addTab(tabLayout.newTab().setText(tabText[i]));
        }
        mViewPager.setAdapter(adapter);
        mViewPager.setOffscreenPageLimit(2);
        tabLayout.setupWithViewPager(mViewPager);
        tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                mViewPager.setCurrentItem(tab.getPosition(),false);
//                mViewPager.getAdapter().notifyDataSetChanged();
            }
            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
            }
            @Override
            public void onTabReselected(TabLayout.Tab tab) {
            }
        });
    }

    @Override
    public String setupToolBarTitle() {
        return "意见反馈";
    }

    @Override
    public boolean setupToolBarLeftButton(ImageView leftButton) {
        return true;
    }


    @OnClick(R.id.toolbar_leftbtn)
    void onToolbarLeft() {
        finish();
    }

}
